<template>
	<view class="container">
		<!-- 		<view class="list-cell b-b m-t" @click="navTo('/package_mall/pages/set/setUserInfo')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">个人资料</text>
			<text class="cell-more yticon icon-you"></text>
		</view> -->
		<!-- 		<view class="list-cell b-b" @click="navTo('/package_mall/pages/set/setUserSecurity')" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit">账户安全</text>
			<text class="cell-more yticon icon-you"></text>
		</view> -->
		<!-- <view class="list-cell m-t">
			<text class="cell-tit">消息推送</text>
			<switch :checked="userInfo.notificationEnabled" color="#fa436a" @change="switchChange" />
		</view> -->
		<view class="list-cell  b-b">
			<text class="cell-tit">当前版本</text>
			<text class="cell-tip">1.0.0</text>
		</view>
		<view class="list-cell  b-b" hover-class="cell-hover" :hover-stay-time="50">
			<text class="cell-tit" @click="navTo('/package_mall/pages/help/help')">常见问题</text>
			<text class="cell-more yticon icon-you"></text>
		</view>
		<!-- 		<view class="list-cell" @click="navTo('/package_mall/pages/set/setAbout')" hover-class="cell-hover"
		 :hover-stay-time="50">
			<text class="cell-tit">关于我们</text>
			<text class="cell-more yticon icon-you"></text>
		</view> -->
		<view class="list-cell log-out-btn" @click="toLogout" v-if="hasLogin">
			<text class="cell-tit">退出登录</text>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {

			};
		},
		onLoad() {

		},
		computed: {
			...mapState(['hasLogin', 'userInfo', 'weChatSetting'])
		},
		methods: {
			...mapMutations(['logout', 'clearFootPrint', 'updateWeCahtSetting']),

			getWeChatSetting() {
				let appId = uni.getStorageSync("appId")
				let params = {
					"appId": appId
				}
				//获取应用全局设置
				this.$api.request.getWeChatSettingInfo(params, res => {
					if (res.body.status.statusCode === '0') {
						this.updateWeCahtSetting(res.body.data.weChatSetting); //将全局设置保存起来
					} else {
						console.log('获取微信小程序设置信息失败');
					}
				});
			},

			navTo(url) {
				uni.navigateTo({
					url: url
				})
			},

			//退出登录
			toLogout() {
				uni.showModal({
					content: '确定要退出登录么',
					success: (e) => {
						if (e.confirm) {
							this.clearFootPrint();
							this.logout();
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/index/index'
								})
							}, 300)
						}
					}
				});
			},
			//打开或关闭消息通知
			switchChange(e) {
				let isNotificationEnabled = e.detail.value ? true : false;
				if (isNotificationEnabled)
					this.$api.request.enableNotification({
						userUuid: this.userInfo.userUuid,
					}, res => {});
				else
					this.$api.request.disableNotification({
						userUuid: this.userInfo.userUuid,
					}, res => {});
			},
		},




	}
</script>

<style lang='scss'>
	page {
		background: $page-color-base;
	}

	.list-cell {
		display: flex;
		align-items: baseline;
		padding: 20upx $page-row-spacing;
		line-height: 60upx;
		position: relative;
		background: #fff;
		justify-content: center;

		&.log-out-btn {
			margin-top: 40upx;

			.cell-tit {
				color: $uni-color-primary;
				text-align: center;
				margin-right: 0;
			}
		}

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		&.m-t {
			margin-top: 16upx;
		}

		.cell-more {
			align-self: baseline;
			font-size: $font-lg;
			color: $font-color-light;
			margin-left: 10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: $font-base + 2upx;
			color: $font-color-dark;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: $font-base;
			color: $font-color-light;
		}

		switch {
			transform: translateX(16upx) scale(.84);
		}
	}
</style>
